# coding = utf-8

'''
针对图像的分析处理
'''

import cv2,os
import numpy as np
import matplotlib.pyplot as plt
import SimpleITK as sitk
from PIL import Image
import math


def find_data(case_id, origion_id, index):
    big_image = "E:\Dataset\Liver\qiye\DongBeiDaXue2\image_venous\\data2_{}_venous.mha".format(origion_id)
    big_liver = "E:\Dataset\Liver\qiye\DongBeiDaXue2\liver\\data2_{}_liver_label.mha".format(origion_id)
    big_tumor = "E:\Dataset\Liver\qiye\DongBeiDaXue2\lesion\\data2_{}_lesion_label.mha".format(origion_id)
    big_fusion = "E:\predict\image_tumor\case_{}\\fusion\\{}.png".format(str(case_id).zfill(5), str(index).zfill(3))
    big_image = sitk.GetArrayFromImage(sitk.ReadImage(big_image))
    big_image = big_image[index]
    big_liver = sitk.GetArrayFromImage(sitk.ReadImage(big_liver))
    big_liver = big_liver[index]
    big_tumor = sitk.GetArrayFromImage(sitk.ReadImage(big_tumor))
    big_tumor = big_tumor[index]
    big_fusion = Image.open(big_fusion)
    return (big_image, big_fusion, big_liver, big_tumor)

def show_truncate():
    (big_image, big_fusion, big_liver, big_tumor) = find_data(case_id=74, origion_id="0656", index=40)
    (middle_image, middle_fusion, middle_liver, middle_tumor) = find_data(case_id=67, origion_id="0415", index=135)
    (small_image, small_fusion, small_liver, small_tumor) = find_data(case_id=79, origion_id="0865", index=262)
    (little_image, little_fusion, little_liver, little_tumor) = find_data(case_id=72, origion_id="0628", index=142)

    c1 = little_image.copy()
    little_image[little_image<=-250] = -250
    little_image[little_image>=250] = 250

    c1[c1<=60] = 60
    c1[c1>=600] = 600

    plt.subplot(1, 3, 1)
    plt.imshow(little_image, cmap="gray")
    plt.subplot(1, 3, 2)
    plt.imshow(c1, cmap="gray")
    plt.subplot(1, 3, 3)
    plt.imshow(little_fusion)
    plt.show()




if __name__ == '__main__':
    show_truncate()